class Solution:
    class UnionFind:
        def __init__(self):
            self.parent = list(range(26))

        def find(self, index):
            if index == self.parent[index]:
                return index
            self.parent[index] = self.find(self.parent[index])
            return self.parent[index]

        def union(self, index1, index2):
            self.parent[self.find(index1)] = self.find(index2)
    def equationPossible(self,equations):
        uf=Solution.UnionFind()
        for st in equations:
            if st[1]=='=':
                index1=ord(st[0])-ord('a')
                index2=ord(st[3])-ord('a')
                uf.union(index1,index2)
        for st in equations:
            if st[1]=='!':
                index1=ord(st[0])-ord('a')
                index2=ord(st[3])-ord('a')
                if uf.find(index1)==uf.find(index2):
                    return False
        return True

sol=Solution()
print(sol.equationPossible(["b==a","a==b"]))
# for str in 'abc':
#     print(ord(str),end=' ')
# print(sol.equationPossible(["a==b","b==c","a==c"]))
# print(sol.equationPossible(["a==b","b!=c","c==a"]))